/**
 * 
 */
package com.xpec.c4.game.utility;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * 自動產生大量連號字串
 * 
 * @author TW15010
 */
public class TextWithSerialNumberGenernator {
	static String readFile(String path, Charset encoding) throws IOException {
		byte[] encoded = Files.readAllBytes(Paths.get(path));
		return new String(encoded, encoding);
	}

	public static void main(String[] args) {
		/*
		指定文字範本檔案名稱

		text file example:
		
		ALTER TABLE `halloween_jackpotlog_%d`
			ADD COLUMN `hjplost` DECIMAL(19,2) NULL DEFAULT '0.00' AFTER `jpZombierand`,
			ADD COLUMN `hjplosttotal` DECIMAL(19,2) NULL DEFAULT '0.00' AFTER `hjplost`;
		*/
		String textFileName = "input.txt";
		String outputFileName = "output.txt";
		
		TextFileWriter writer = new TextFileWriter();
		writer.createFile(outputFileName);
		
		// 開始數字
		int begReplaceNumber = 1;
		
		// 結束數字
		int endReplaceNumber = 12;
		
		// 結果會輸出到 console 視窗

		String aa = null;
		try {
			aa = readFile(textFileName, Charset.defaultCharset());
		} catch (IOException e) {
			e.printStackTrace();
		}

		for (int i = begReplaceNumber; i <= endReplaceNumber; i++) {
			String output = aa.replace("%d", String.valueOf(i));
			System.out.print(output);
			
			writer.writeText(output);
		}
		
		writer.closeFile();
	}
}
